//
//  QZCommentVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/6/18.
//

#import "QZCommentVC.h"
#import "QZCommentModel.h"
#import "QZCommentShowCell.h"
#import "QZCommentShowSubordinateCell.h"
#import "QZCommentFootView.h"
#import "DCComPicViewController.h"
#import "DCFiltrateViewController.h"
#import "DJCommentInputView.h"
#import "CSJADLoading.h"
#import "DJMYBIVC.h"
#import "PublicView.h"

@interface QZCommentVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic)UITableView * commentTableView;
@property (strong, nonatomic)UIView * adView;
@property (strong, nonatomic)UILabel * numberLabel;
@property (strong, nonatomic) UIButton * inputCommetView;
@property (strong, nonatomic)NSMutableArray <QZCommentModel *>* commentArr;
@property (nonatomic, assign) CGFloat videoHeight;
@property (nonatomic, assign) NSInteger videoPage;
@property (nonatomic, strong) PublicView * nullView;
@property (nonatomic, strong) UIView * headerBg;
@property (nonatomic, assign) BOOL isNotOne;
@end

@implementation QZCommentVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if(self.isNotOne){
        self.commentPushViewControlBlock(NO);
    }else{
        self.isNotOne = YES;
    }
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = viewback_black;
    self.additionalSafeAreaInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.videoHeight = KScreen_H-(KScreen_H-KTab_H)*0.35;
    [self configUI];
    KWeakSelf
    [CSJADLoading share].BannerAdsLoadFish = ^(id  _Nullable bannerView) {
        if(bannerView != nil && weakSelf.adView){
            weakSelf.headerBg.frame = CGRectMake(0, 0, KScreen_W, 95);
            weakSelf.adView.frame = CGRectMake(0, 48, KScreen_W, 45);
            weakSelf.commentTableView.frame = CGRectMake(0, 95, KScreen_W, weakSelf.videoHeight-150);
            [weakSelf.adView addSubview:bannerView];
            [bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(weakSelf.adView);
            }];
            [UIView animateWithDuration:0.3 animations:^{
                [weakSelf.view layoutIfNeeded];
            }];
        }
    };
    [CSJADLoading ADBannerAdRequest:self];
}
- (PublicView *)nullView{
    if(_nullView == nil){
        _nullView = [[PublicView alloc]initWithFrame:CGRectMake(0, (self.videoHeight-200)/2, KScreen_W, 200)];
        _nullView.publicLabel.text = @"暂无评论";
        _nullView.hidden = YES;
        _nullView.userInteractionEnabled = NO;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_nullView];
    }
    return _nullView;
}
- (void)configUI{
    
    KWeakSelf
    self.commentTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        weakSelf.videoPage ++;
        [weakSelf requestDatas];
    }];
    self.numberLabel.text = [NSString stringWithFormat:@"%ld条评论",self.numberIndex];
//    self.commentTableView.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
//        //下拉刷新要做的操作.
//        NSLog(@"下拉");
//        [weakSelf.commentTableView.mj_footer resetNoMoreData];
//        [weakSelf.commentArr removeAllObjects];
//        [weakSelf.commentTableView reloadData];
//        weakSelf.videoPage = 0;
//        [weakSelf requestDatas];
//    }];
    [weakSelf requestDatas];
    
    [self.inputCommetView addTarget:self action:@selector(commentTap) forControlEvents:UIControlEventTouchUpInside];
    
}
#pragma mark 初始化
- (UIButton *)inputCommetView{
    if(_inputCommetView == nil){

        UIView * footView = [[UIView alloc]initWithFrame:CGRectMake(0,  self.videoHeight-47-KSafeAreaBottomHeight, KScreen_W, 47+KSafeAreaBottomHeight)];
        footView.backgroundColor = viewback_black;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:footView];
        
        _inputCommetView = [[UIButton alloc]init];
        _inputCommetView.frame = CGRectMake(15, self.videoHeight-47-KSafeAreaBottomHeight, KScreen_W-30, 44);
        [_inputCommetView setTitle:@"    有爱评论，说点儿好听的~" forState:UIControlStateNormal];
        [_inputCommetView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _inputCommetView.titleLabel.font = Font(15);
        _inputCommetView.backgroundColor = subviewback_black;
        _inputCommetView.layer.cornerRadius = 12;
        _inputCommetView.clipsToBounds = YES;
           UILabel * oldshowSSSSTip1 = [[UILabel alloc]init];
    oldshowSSSSTip1.clipsToBounds = YES;
    oldshowSSSSTip1.text = @"kass显示区";
    oldshowSSSSTip1.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip1.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip1.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip1.hidden = YES;
    [self.view addSubview:oldshowSSSSTip1];
    [self.view addSubview:_inputCommetView];
    }
    return _inputCommetView;
}
- (UILabel *)numberLabel{
    if(_numberLabel == nil){
        _headerBg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, 48)];
        _headerBg.backgroundColor = viewback_black;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_headerBg];
        
        _adView = [[UIView alloc]init];
        _adView.frame = CGRectMake(0, 48, KScreen_W, 0);
        _adView.backgroundColor = [UIColor whiteColor];
           UILabel * oldshowSSSSTip1 = [[UILabel alloc]init];
    oldshowSSSSTip1.clipsToBounds = YES;
    oldshowSSSSTip1.text = @"kass显示区";
    oldshowSSSSTip1.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip1.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip1.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip1.hidden = YES;
    [self.view addSubview:oldshowSSSSTip1];
    [self.view addSubview:_adView];
        
        _numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, 48)];
        _numberLabel.textColor = [UIColor whiteColor];
        _numberLabel.font = FontBold(14);
        _numberLabel.textAlignment = NSTextAlignmentCenter;
           UILabel * oldshowSSSSTip2 = [[UILabel alloc]init];
    oldshowSSSSTip2.clipsToBounds = YES;
    oldshowSSSSTip2.text = @"kass显示区";
    oldshowSSSSTip2.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip2.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip2.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip2.hidden = YES;
    [self.view addSubview:oldshowSSSSTip2];
    [self.view addSubview:_numberLabel];
    }
    return _numberLabel;
}
- (UITableView *)commentTableView{
    if(_commentTableView == nil){
        _commentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 48, KScreen_W, self.videoHeight-100) style:UITableViewStyleGrouped];
        
//        _commentTableView.safeAreaInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        _commentTableView.separatorInset = UIEdgeInsetsZero;
//        _commentTableView.sectionHeaderHeight = 0.0;
        _commentTableView.estimatedSectionHeaderHeight = 0.0;
//        _commentTableView.sectionFooterHeight = 0.0;
        _commentTableView.estimatedSectionFooterHeight = 0.0;
//        _commentTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _commentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _commentTableView.backgroundColor = [UIColor clearColor];
        _commentTableView.delegate = self;
        _commentTableView.dataSource = self;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_commentTableView];
        
        _commentTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    return _commentTableView;
}
- (NSMutableArray<QZCommentModel *> *)commentArr{
    if(_commentArr == nil){
        _commentArr = [NSMutableArray new];
    }
    return _commentArr;
}
#pragma mark 请求
- (void)requestDatas{
    KMutableDic(sendDic)
    [sendDic setObject:self.videoId forKey:@"videoid"];
    [sendDic setObject:@(self.videoPage) forKey:@"page"];
    KWeakSelf
    [YBNetBase commentParentplListVideosRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [SVProgressHUDTool dismiss];
            for (NSDictionary * dic in data[@"list"]) {
                QZCommentModel * model = [[QZCommentModel alloc]init];
                model.fmid = weakSelf.mId;
                [model setValuesForKeysWithDictionary:dic];
                [weakSelf.commentArr addObject:model];
                
            }
            [weakSelf.commentTableView reloadData];
            if(weakSelf.commentArr.count == 0){
                weakSelf.nullView.hidden = NO;
                weakSelf.commentTableView.clipsToBounds = YES;
            }else{
                weakSelf.nullView.hidden = YES;
                weakSelf.commentTableView.clipsToBounds = NO;
            }
            if([data[@"list"] count] == 0){
                [weakSelf.commentTableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                [weakSelf.commentTableView.mj_footer endRefreshing];
            }
        }else{
            [YBMsgPop showPop:msg];
            [weakSelf tableEndFiresh];
        }
        
    }];
}
- (void)launchComment:(NSInteger)section{
    KMutableDic(sendDic)
    [sendDic setObject:self.videoId forKey:@"videoid"];
    [sendDic setObject:self.commentArr[section].comid forKey:@"comid"];
    [sendDic setObject:@(self.commentArr[section].comPage) forKey:@"page"];
    [sendDic setObject:@(10) forKey:@"page_num"];
    KWeakSelf
    [YBNetBase commentSonplListVideosRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [SVProgressHUDTool dismiss];
            for (NSDictionary * dic in data[@"list"]) {
                weakSelf.commentArr[section].isOpen = YES;
                weakSelf.commentArr[section].comPage = weakSelf.commentArr[section].comPage+1;
                
                QZCommentModel * model = [[QZCommentModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                model.fmid = weakSelf.mId;
                [weakSelf.commentArr[section].subCommenArr addObject:model];
            }
            [weakSelf.commentTableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
-(void)showTextViewAddShowViewTo2{
    UIView * showTextViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 100, 360)];
    showTextViewViewTo1.backgroundColor = [UIColor whiteColor];
    showTextViewViewTo1.layer.cornerRadius = 8;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewViewTo1];
    
    UIImageView * showTextViewimgTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(K_AUTOLAYOUT_W(157.5), K_AUTOLAYOUT_W(260), K_AUTOLAYOUT_W(60), K_AUTOLAYOUT_W(60))];
    showTextViewimgTo2.layer.cornerRadius = K_AUTOLAYOUT_W(30);
    showTextViewimgTo2.clipsToBounds = YES;
    showTextViewimgTo2.contentMode = UIViewContentModeScaleAspectFill;
    showTextViewimgTo2.hidden = YES;
    [showTextViewViewTo1 addSubview:showTextViewimgTo2];
    
    UILabel *  showTextViewimgTo3 = [[UILabel alloc]initWithFrame:CGRectMake(K_AUTOLAYOUT_W(15), K_AUTOLAYOUT_W(35), K_AUTOLAYOUT_W(345), K_AUTOLAYOUT_W(25))];
    showTextViewimgTo3.font = FontBold(18);
    showTextViewimgTo3.textColor = ThreeColor;
    showTextViewimgTo3.textAlignment = NSTextAlignmentCenter;
    showTextViewimgTo3.hidden = YES;
    [showTextViewViewTo1 addSubview:showTextViewimgTo3];
}
- (NSString *)showTextViewGetNowTimerTo3{
    NSDateFormatter *showTextViewGetNowFa = [[NSDateFormatter alloc] init];
    [showTextViewGetNowFa setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [showTextViewGetNowFa stringFromDate:[NSDate date]];
}

- (void)tableEndFiresh{
    if([self.commentTableView.mj_header isRefreshing]){
        [self.commentTableView.mj_header endRefreshing];
    }
    if([self.commentTableView.mj_footer isRefreshing]){
        [self.commentTableView.mj_footer endRefreshing];
    }
}
- (void)commetPost:(NSString *)contenStr type:(NSInteger)type comid:(id)comid index:(NSIndexPath *)index{
    KWeakSelf
    KMutableDic(sendDic)
    
    [sendDic setObject:contenStr forKey:@"contents"];
    if(type == 0){
        [sendDic setObject:self.videoId forKey:@"videoid"];
        [YBNetBase commentplVideoRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                QZCommentModel * model = [[QZCommentModel alloc]init];
                [model setValuesForKeysWithDictionary:data[@"com_data"]];
                [weakSelf.commentArr insertObject:model atIndex:0];
                [weakSelf.commentTableView reloadData];
                weakSelf.nullView.hidden = YES;
                weakSelf.commentTableView.clipsToBounds = NO;
                
                weakSelf.numberIndex = weakSelf.numberIndex+1;
                weakSelf.numberLabel.text = [NSString stringWithFormat:@"%ld条评论",self.numberIndex];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
        
    }else{
        [sendDic setValue:comid forKey:@"comid"];
        [sendDic setObject:self.videoId forKey:@"videoid"];
        [YBNetBase commentplCommentRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                QZCommentModel * model = [[QZCommentModel alloc]init];
                [model setValuesForKeysWithDictionary:data[@"com_data"]];
                model.fmid = weakSelf.mId;
                [weakSelf.commentArr[index.section].subCommenArr insertObject:model atIndex:0];
                [weakSelf.commentTableView reloadData];
                weakSelf.numberIndex = weakSelf.numberIndex+1;
                weakSelf.numberLabel.text = [NSString stringWithFormat:@"%ld条评论",self.numberIndex];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }
}
#pragma mark uitableview delege
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.commentArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.commentArr[section].subCommenArr count]+1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        QZCommentShowCell * cell = [tableView dequeueReusableCellWithIdentifier:@"QZCommentShowCell"];
        if (cell == nil) {
            cell = [[QZCommentShowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"QZCommentShowCell"];
        }
        cell.commentModel = self.commentArr[indexPath.section];
        KWeakSelf
        cell.commenReplyTapBlock = ^(NSInteger index) {
            if(index == 0){
                DJCommentInputView * input = [[DJCommentInputView alloc]init];
                input.tipStr = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"回复", nil),weakSelf.commentArr[indexPath.section].nickname];
                [weakSelf presentPanModal:input];
                input.commentSaveBlock = ^(NSString * _Nonnull saveStr) {
                    [weakSelf commetPost:saveStr type:1 comid:weakSelf.commentArr[indexPath.section].comid index:indexPath];
                };
            }else if (index == 1){
                [weakSelf commentFanYiRequest:weakSelf.commentArr[indexPath.section]];
            }else if (index == 2){
                [QZUserInfoModel otherMineControlView:[Tools currentActiveController] mineId:weakSelf.commentArr[indexPath.section].mid videoId:nil];
            }
        };
        return cell;
    }else{
        QZCommentShowSubordinateCell * cell = [tableView dequeueReusableCellWithIdentifier:@"QZCommentShowSubordinateCell"];
        if (cell == nil) {
            cell = [[QZCommentShowSubordinateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"QZCommentShowSubordinateCell"];
        }
        cell.commentModel = self.commentArr[indexPath.section].subCommenArr[indexPath.row-1];
        KWeakSelf
        cell.commentSubordinateReplyTapBlock = ^(NSInteger index) {
            if(index == 0){
                DJCommentInputView * input = [[DJCommentInputView alloc]init];
                input.tipStr = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"回复", nil),weakSelf.commentArr[indexPath.section].subCommenArr[indexPath.row-1].nickname];
                [weakSelf presentPanModal:input];
                input.commentSaveBlock = ^(NSString * _Nonnull saveStr) {
                    [weakSelf commetPost:saveStr type:1 comid:weakSelf.commentArr[indexPath.section].subCommenArr[indexPath.row-1].comid index:indexPath];
                };
            }else if (index == 1){
                [weakSelf commentFanYiRequest:weakSelf.commentArr[indexPath.section].subCommenArr[indexPath.row-1]];
            }else if (index == 2){
                [QZUserInfoModel otherMineControlView:[Tools currentActiveController] mineId:weakSelf.commentArr[indexPath.section].mid videoId:nil];
            }
        };
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if([self.commentArr[section].plnum intValue] != 0){
        return 44;
    }else{
        return 0.01;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if([self.commentArr[section].plnum intValue] != 0){
        QZCommentFootView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"QZCommentFootView"];
        if(footer == nil){
            footer = [[QZCommentFootView alloc]initWithReuseIdentifier:@"QZCommentFootView"];
        }
        if([self.commentArr[section].plnum intValue] > self.commentArr[section].subCommenArr.count){
            if(self.commentArr[section].isOpen == NO){
                footer.launchStr = [NSString stringWithFormat:@"展示%@条回复",self.commentArr[section].plnum];
            }else{
                footer.launchStr = @"展开更多";
            }
        }else{
            footer.launchStr = @"";
        }
        if(self.commentArr[section].subCommenArr.count == 0){
            footer.isShowputAway = YES;
        }else{
            footer.isShowputAway = NO;
        }
        KWeakSelf
        footer.commentFootTapBlock = ^(NSInteger index) {
            if(index == 0){
                [weakSelf launchComment:section];
            }else if (index == 1){
                weakSelf.commentArr[section].isOpen = NO;
                weakSelf.commentArr[section].comPage = 0;
                [weakSelf.commentArr[section].subCommenArr removeAllObjects];
                [tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone];
            }
        };
        return footer;
    }else{
        return nil;
    }
}
#pragma mark 操作区域
- (void)gooddetail{
    DCFiltrateViewController * vc = [[DCFiltrateViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)commentTap{
    DJCommentInputView * input = [[DJCommentInputView alloc]init];
    input.tipStr = NSLocalizedString(@"有爱评论，说点好听的", nil);
    [self presentPanModal:input];
    KWeakSelf
    input.commentSaveBlock = ^(NSString * _Nonnull saveStr) {
        [weakSelf commetPost:saveStr type:0 comid:nil index:[NSIndexPath indexPathForRow:0 inSection:0]];
    };
}
- (void)commentFanYiRequest:(QZCommentModel *)model{
    KMutableDic(sendDic)
    [sendDic setObject:model.comid forKey:@"comment_id"];
    [sendDic setObject:model.videoid forKey:@"videoid"];
    [sendDic setObject:model.contents forKey:@"content"];
    [SVProgressHUDTool showWithStatus:nil];
    KWeakSelf
    [YBNetBase commentFanYiRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        [SVProgressHUDTool dismiss];
        if(code == 200){
            model.contents = data[@"translate_text"];
            [weakSelf.commentTableView reloadData];
            [YBMsgPop showPop:@"翻译成功"];
        }else if (code == 1201){
            DJMYBIVC * bi = [[DJMYBIVC alloc]init];
            bi.modalPresentationStyle = UIModalPresentationFullScreen;
            bi.isPre= YES;
            [[Tools currentActiveController] presentViewController:bi animated:YES completion:^{
                [YBMsgPop showPop:@"金币不足,请充值"];
            }];
            weakSelf.commentPushViewControlBlock(YES);
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
#pragma mark - HWPanModalPresentable
- (void)panModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer dismissPercent:(CGFloat)percent{
    UIView * view = panGestureRecognizer.view;
    if(![view isKindOfClass:[UITableView class]]){
        CGFloat yDisplacement = [panGestureRecognizer translationInView:view.superview].y;
        self.commentMoveStatusBlock(percent*self.videoHeight, NO);
    }
    
    
}
- (BOOL)shouldRespondToPanModalGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer{
//    CGPoint loc = [panGestureRecognizer locationInView:self.commentTableView];
//    if(!CGRectContainsPoint(self.commentTableView.frame, loc)){
//        NSLog(@"555555");
//    }else{
//        NSLog(@"555556");
//    }
//    return !CGRectContainsPoint(self.commentTableView.frame, loc);
    CGPoint loc = [panGestureRecognizer locationInView:self.view];
    return !CGRectContainsPoint(self.view.frame, loc);
}
- (void)didChangeTransitionToState:(PresentationState)state{
    if(self.commentMoveStatusBlock){
        self.commentMoveStatusBlock(0, YES);
    }
}

- (void)panModalWillDismiss{
    if(self.commentMoveStatusBlock){
        self.commentMoveStatusBlock(self.videoHeight, YES);
    }
}


- (PanModalHeight)longFormHeight {
    return PanModalHeightMake(PanModalHeightTypeMax, 0);
}

- (HWBackgroundConfig *)backgroundConfig{
    HWBackgroundConfig *config = [HWBackgroundConfig new];
    config.backgroundAlpha = 0;
    return config;
}


- (CGFloat)cornerRadius{
    return 16;
}

- (CGFloat)topOffset{
    return (KScreen_H-KTab_H)*0.35;
}

- (PanModalHeight)shortFormHeight {
    return [self longFormHeight];
}

- (UIScrollView *)panScrollable {
    return self.commentTableView;
}

- (BOOL)isAutoHandleKeyboardEnabled{
    return NO;
}

- (BOOL)showsScrollableVerticalScrollIndicator {
    return NO;
}

- (BOOL)showDragIndicator{
    return NO;
}

@end
